
<template>
  <elm-page-bb class="elm-list-edit">
    <elm-page-tb :splite="false" :splite-show="false">
      <template #top>
        <right>
          <el-button-group>
            <el-button size="mini" @click="add">新增</el-button>
          </el-button-group>
        </right>
      </template>
      <elm-table ref="table" url="/business/my/ei/career/GetData" :post-data="postData" :page-size="9999" height="100%">
        <el-table-column :label="request.type" align="center">
          <template v-slot="scope">
            <el-form size="small" label-width="120px">
              <elm-row>
                <el-form-item label="开始日期">
                  <el-date-picker v-model="scope.row.sdate"  value-format="yyyy-MM-dd" type="date" style="width: 100%">
                  </el-date-picker>
                </el-form-item>
                <el-form-item label="结束日期">
                  <el-date-picker v-model="scope.row.edate"  value-format="yyyy-MM-dd" type="date" style="width: 100%">
                  </el-date-picker>
                </el-form-item>
              </elm-row>
              <elm-row>
                <el-form-item :label="request.type=='教育背景'?'学校名称':'工作单位'">
                  <el-input v-model="scope.row.org"></el-input>
                </el-form-item>
                <el-form-item :label="request.type=='教育背景'?'学习专业':'担任职务'">
                  <el-input v-model="scope.row.major"></el-input>
                </el-form-item>
              </elm-row>
              <elm-row v-if="request.type=='教育背景'">
                <el-form-item label="学历">
                  <el-select v-model="scope.row.diploma"  style="width: 100%" clearable>
                    <el-option key="本科" label="本科" value="本科"></el-option>
                    <el-option key="研究生" label="研究生" value="研究生"></el-option>
                    <el-option key="大专" label="大专" value="大专"></el-option>
                    <el-option key="博士" label="博士" value="博士"></el-option>
                    <el-option key="中专" label="中专" value="中专"></el-option>
                  </el-select>
                </el-form-item>
                <el-form-item label="备注">
                  <el-input v-model="scope.row.remark"></el-input>
                </el-form-item>
              </elm-row>
              <el-form-item :label="request.type=='教育背景'?'主修课程':'主要业绩'">
                <el-input type="textarea" :rows="3" v-model="scope.row.results"></el-input>
              </el-form-item>
            </el-form>
          </template>
        </el-table-column>
        <el-table-column fixed="right" label="操作" width="80px" align="center">
          <template v-slot="scope">
            <el-button @click="del(scope.row)"  type="text" size="mini">删除</el-button>
          </template>
        </el-table-column>
      </elm-table>
    </elm-page-tb>
    <template #bottom>
      <el-button type="success" size="small" @click="submit">立即保存</el-button>
      <el-button size="small" @click="close">取消</el-button>
    </template>
  </elm-page-bb>
</template>

<script>
export default {
  extends: elmVueBase,
  data() {
    return {
      postData:{type:null,ei_id:null}
    }
  },
  created() {
    this.postData.ei_id=this.request.ei_id;
    this.postData.type=this.request.type;
  },
  methods: {
    add() {
      this.$refs.table.datalist.push({type:this.request.type,ei_id:this.request.ei_id,
        diploma:null,results:null,remark:null,org:null,major:null,sdate:null,edate:null});
    },
    async del(item)
    {
      if(item.id!=undefined)
      {
        await elm.post("/business/my/ei/career/Delete",{ id: item.id});
      }
      this.$refs.table.datalist = this.$refs.table.datalist.filter(p => !(p==item));
    },
    async submit()
    {
      var ret = await elm.post("/business/my/ei/career/Save",
          {items:this.$refs.table.datalist,ei_id:this.request.ei_id,type:this.request.type});
      if(ret>0)
      {
        this.close();
        this.v("保存成功。");
        this.request.callVue.init_career(this.request.type);
      }
    }
  }
}
</script>
